home *** CD-ROM | disk | FTP | other *** search
/ APC & TCP 4 / APC & TCP 4.iso / games / publicdomain / a / attacks / sources / attacksgraphics.mod < prev    next >
Text File  |  1994-05-14  |  45KB  |  1,089 lines

  1. IMPLEMENTATION MODULE attacksgraphics;
  2.  
  3. (*$R-V-*) (* range checking OFF, overflow checking OFF *)
  4.  
  5. (* This is the implementation module of all the graphics stuff for my
  6.   ataxx program.
  7. *)
  8.  
  9. (**************************************************************)
  10. FROM TermInOut
  11.   IMPORT   WriteString, WriteLn;
  12.  
  13. FROM SYSTEM
  14.   IMPORT   BYTE, ADR, LONGWORD, ADDRESS;
  15.  
  16. FROM Memory
  17.   IMPORT   AllocMem, FreeMem, MemReqSet, MemChip, MemClear;
  18.  
  19. FROM Preferences
  20.   IMPORT   Preferences, GetPrefs;
  21.  
  22. FROM Views
  23.   IMPORT   ViewModesSet, Sprites, LoadRGB4, SetRGB4, ViewPort, ColorTable,
  24.            GetRGB4;
  25.  
  26. FROM Rasters
  27.   IMPORT   RastPort, Jam1, Jam2;
  28.  
  29. FROM Drawing
  30.   IMPORT   SetAPen, SetOPen, SetDrMd, Draw, Move, RectFill, DrawCircle,
  31.            WritePixel, ReadPixel;
  32.  
  33. FROM header
  34.   IMPORT   boardtype, playertype, squaretype, boardrange, state, pointercode,
  35.            movetype, printmsgtype;
  36.  
  37. FROM input
  38.   IMPORT   WaitForMouseUp, ChangeToMainMenu;
  39.  
  40. FROM attackssprites
  41.   IMPORT   InitPointers, circle, mypointer, emptysquare, blocksquare;
  42.  
  43. FROM Ports
  44.   IMPORT   GetMsg, ReplyMsg, MsgPortPtr, WaitPort, MessagePtr;
  45.  
  46. FROM Conversions
  47.   IMPORT   ConvNumberToString;
  48.  
  49. FROM Intuition
  50.   IMPORT   NewScreen, OpenScreen, ScreenPtr, Screen, CustomScreen,
  51.            CloseScreen, NewWindow, WindowPtr, WindowFlagsSet,
  52.            IDCMPFlagsSet, OpenWindow, CloseWindow, ClearMenuStrip,
  53.            WindowFlags, IDCMPFlags, ScreenFlags, IntuiMessagePtr,
  54.            SetPointer, ClearPointer, IntuiText, PrintIText, ShowTitle;
  55.  
  56. (***********************************************************************)
  57.  
  58. CONST
  59.   Black = 0;
  60.   White = 1;
  61.   BGrey = 2;
  62.  
  63.   Red   = 3;     DarkRed = 4;      LtRed = 5;
  64.   Blue  = 6;     DarkBlue = 7;     LtBlue = 8;
  65.   HGrey = 9;     HDarkGrey = 10;   HLtGrey = 11;
  66.  
  67.   Green = 14;    DarkGreen = 13;   LtGreen = 12;     (* other colors *)
  68.   Yellow = 15;   DarkYellow = 16;  LtYellow = 18;
  69.   Orange = 18;   DarkOrange = 19;  LtOrange = 20;
  70.   Purple = 21;   DarkPurple = 22;  LtPurple = 23;
  71.   Violet = 24;   DarkViolet = 25;  LtViolet = 26;
  72.   Cyan = 27;     DarkCyan = 28;    LtCyan = 29;
  73.  
  74. VAR
  75.   ns : NewScreen;               (* The screen and graphics vars  *)
  76.   myscreenptr : ScreenPtr;
  77.   myrastport : RastPort;
  78.   myviewport : ViewPort;
  79.   mycolortable : ColorTable;
  80.  
  81.   nw : NewWindow;               (* The backdrop window vars      *)
  82.  
  83.   itext : IntuiText;            (* For displaying text  *)
  84.  
  85.   oldmousecolor1, oldmousecolor2, oldmousecolor3 :   (* Hold the colors  *)
  86.      ARRAY [1..3] OF CARDINAL;                       (* of the original   *)
  87.                                                      (* mouse.            *)
  88.  
  89. (**************************************************************************)
  90.  
  91. PROCEDURE InitializeScreen() : BOOLEAN;
  92.  
  93. (*      Starts the graphix running.                                    *)
  94. (* Sets up all the graphics variables and draws the first graphics     *)
  95. (* that will be presented.  It returns true if all the actions worked, *)
  96. (* false otherwise.                                                    *)
  97. (*                                                                     *)
  98. (*   INPUT                                                             *)
  99. (*            n/a                                                      *)
  100. (*                                                                     *)
  101. (*   OUTPUT                                                            *)
  102. (*            Returns a boolean value that tells if the operation was  *)
  103. (*            succussful or not.  If successful, the screen (along     *)
  104. (*            with the accompanying graphics) is started.              *)
  105. (*                                                                     *)
  106. (*   NOTE:    This uses mostly globals to this module.  It should      *)
  107. (*            work fine.                                               *)
  108.  
  109. VAR
  110.   i : CARDINAL;
  111.   oldcolor : LONGCARD;             (* holds the initial result of GetRGB4 *)
  112.   preferences : Preferences;
  113.   foo : ADDRESS;
  114.  
  115. BEGIN
  116.       (*******************************)
  117.       (* Making new screen structure *)
  118.       (*******************************)
  119.  
  120.   ns.LeftEdge := 0; ns.TopEdge := 0;
  121.   ns.Width := 320; ns.Height := 200;
  122.   ns.Depth := 4;
  123.   ns.DetailPen := BYTE(0); ns.BlockPen := BYTE(1);
  124.   ns.ViewModes := ViewModesSet{Sprites};    (* Not quite sure about this *)
  125.   ns.Type := CustomScreen;
  126.   ns.Font := NIL;                           (* Using default font *)
  127.   ns.DefaultTitle := ADR("Attacks");
  128.   ns.Gadgets := NIL;
  129.  
  130.   myscreenptr := OpenScreen(ns);
  131.   IF myscreenptr = NIL THEN
  132.      WriteString ("Couldn't open screen."); WriteLn;
  133.      RETURN FALSE;
  134.      END;
  135.  
  136.   ShowTitle(myscreenptr^, FALSE);     (* Put title BEHIND the backdrop's *)
  137.  
  138.  
  139.         (**************************************)
  140.         (* Get vars for the graphics routines *)
  141.         (**************************************)
  142.  
  143.   myrastport := myscreenptr^.RastPort;
  144.   myviewport := myscreenptr^.ViewPort;
  145.  
  146.   foo := GetPrefs(ADR(preferences), SIZE(Preferences));
  147.            (* Here, I'm getting the default colors for the orig. mouse *)
  148.   oldmousecolor1[1] := preferences.color17 DIV 128;
  149.   oldmousecolor1[2] := preferences.color17 DIV 8;
  150.   oldmousecolor1[3] := preferences.color17;
  151.   oldmousecolor2[1] := preferences.color18 DIV 128;
  152.   oldmousecolor2[2] := preferences.color18 DIV 8;
  153.   oldmousecolor2[3] := preferences.color18;
  154.   oldmousecolor3[1] := preferences.color19 DIV 128;
  155.   oldmousecolor3[2] := preferences.color19 DIV 8;
  156.   oldmousecolor3[3] := preferences.color19;
  157.  
  158.         (************************************)
  159.         (* Preparing the ColorMap structure *)
  160.         (************************************)
  161.  
  162.                                       (* Defining the colors *)
  163.   mycolortable [0] := 0000H;   (* Black *)
  164.   mycolortable [1] := 0FFFH;   (* White *)
  165.   mycolortable [2] := 0AAAH;   (* BGrey *)
  166.   mycolortable [3] := 0D00H;   (* Red *)
  167.   mycolortable [4] := 0900H;   (* Dark Red *)
  168.   mycolortable [5] := 0F55H;   (* Light Red *)
  169.   mycolortable [6] := 024EH;   (* Blue *)
  170.   mycolortable [7] := 000AH;   (* Dark Blue *)
  171.   mycolortable [8] := 066FH;   (* Light Blue *)
  172.   mycolortable [9] := 0666H;   (* HGrey *)
  173.   mycolortable [10] := 0444H;   (* HDark Grey *)
  174.   mycolortable [11] := 0888H;   (* HLight Grey *)
  175.   mycolortable [12] := 09F9H;   (* Light Green *)
  176.   mycolortable [13] := 0090H;   (* Dark Green *)
  177.   mycolortable [14] := 00E0H;   (* Green *)
  178.   mycolortable [15] := 0EE0H;   (* Yellow *)
  179.  
  180.                                       (* This changes the colors *)
  181.   LoadRGB4 (myviewport, ADR (mycolortable), 16);
  182.  
  183.  
  184.         (*******************************)
  185.         (* Now, open a backdrop window *)
  186.         (*******************************)
  187.  
  188.   nw.LeftEdge := 0; nw.TopEdge := 0;
  189.   nw.Width := 320; nw.Height := 200;
  190.   nw.DetailPen := BYTE(-1); nw.BlockPen := BYTE(-1);  (* use screen's pens *)
  191.   nw.Flags := WindowFlagsSet {BackDrop, Borderless, Activate};
  192.   nw.IDCMPFlags := IDCMPFlagsSet {MouseButtons, MenuPick};
  193.   nw.FirstGadget := NIL;
  194.   nw.CheckMark := NIL;
  195.   nw.Title := NIL;                       (* NO TITLE *)
  196.   nw.Type := CustomScreen;
  197.   nw.Screen := myscreenptr;
  198.  
  199.   mywindowptr := OpenWindow(nw);
  200.   IF mywindowptr = NIL THEN
  201.      CloseScreen(myscreenptr^);
  202.      WriteString ("Couldn't open window."); WriteLn;
  203.      RETURN FALSE;
  204.      END;
  205.  
  206.         (***************************)
  207.         (* Draw the initial screen *)
  208.         (***************************)
  209.  
  210. (* Set the drawing mode *)
  211.   SetDrMd(myrastport, Jam1);
  212.  
  213. (* Blank the screen *)
  214.   SetAPen(myrastport, Black);      (* set A pen *)
  215.   SetOPen(myrastport, Black);      (* and the outline pen too! *)
  216.   RectFill(myrastport,0,0,319,199);
  217.  
  218. (* Drawing a blank board *)
  219. SetAPen(myrastport, BGrey);
  220.   SetOPen(myrastport, BGrey);
  221.   RectFill(myrastport,52,18,267,198);
  222.  
  223.   i := 82;                         (* draw vertical lines *)
  224.   SetAPen(myrastport, Black);      (* black *)
  225.   REPEAT
  226.      Move(myrastport, i, 18);
  227.      Draw(myrastport, i, 199);
  228.      i := i + 31;
  229.   UNTIL i = 268;
  230.  
  231.   i := 43;                         (* now the horizontal *)
  232.   REPEAT
  233.      Move(myrastport, 52, i);
  234.      Draw(myrastport, 268, i);
  235.      i := i + 26;
  236.   UNTIL i = 199;
  237.  
  238.            (*************